
const http = require('http');
const path = require('path');
const url = require('url');
const fs = require('fs')
const router = require('./router');
const config = require('./config');
const util = require('./utils/util');

var server = http.createServer(
    function (request, response) {
    if (request.method.toLowerCase() == 'post') {
        var pathname = url.parse(request.url).path;
        console.log("-------\nPOST: " + pathname);
        console.log(util.datestring(new Date()));
        router.post(pathname, request, response);
    } else if (request.method.toLowerCase() == 'get') {
        var pathname = url.parse(request.url).path;
        console.log("-------\nGET: " + pathname);
        console.log(util.datestring(new Date()));
        router.get(pathname, request, response);
    }
})

server.listen(config.port);
console.log("Server is running...");


